/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;

import javax.swing.JPanel;
import javax.swing.JTextArea;
import maquinaVirtual.MaquinaVirtual;


/**
 *
 * @author David
 */
public  class  MaquinaVirtualThread extends Thread {
    
   private JTextArea ar;
   private Monitor mon;
   private boolean traza;
   private Object[] lista;
   private MaquinaVirtual mv;
   private String ruta;
   
    public MaquinaVirtualThread(JTextArea ar,String root,Monitor mon,boolean traza,Object[] list)
    {
    this.ar=ar;
    this.mon=mon;
    this.traza=traza;
    this.lista= list;
    this.ruta= root;
    }
    public MaquinaVirtualThread(JTextArea ar,String root,Monitor mon,boolean traza)
    {
    this.ar=ar;
    this.mon=mon;
    this.traza=traza;
    this.lista= null;
     this.ruta= root;
    }
    @Override
    public void run(){
        synchronized(this)
        {
         ejecuta();
        }
    }

    public void parar()
    {
        mv.pararTraza();
    }


    private void ejecuta() {
        if(traza)
        {
            mv=new MaquinaVirtual(ruta,true,ar,mon);
            mv.ejecutaMaquinaTrazaGUI(lista);
        }
        else{
        mv=new MaquinaVirtual(ruta,true,ar,mon);
        mv.ejecutaMaquina();
        }
    }

}
